package com.jianjian.system.handler;

import com.jianjian.common.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Zsir
 * @create 2022-10-27 11:21
 */
@ControllerAdvice //通过Aop方式处理异常
public class GlobalExceptionHandler {

    //3.自定义异常处理
    @ExceptionHandler(GuiGuException.class)
    @ResponseBody
    public Result error(GuiGuException e){
        return Result.fail().code(e.getCode()).message(e.getMsg());
    }

    //2.特定异常
    @ExceptionHandler(ArithmeticException.class)
    @ResponseBody
    public Result error(ArithmeticException e){
        return Result.fail("执行特定异常处理--- 不能除零异常处理");
    }



    //1.全局异常
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception exception){
        return Result.fail("执行全局异常处理");
    }

}
